package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.alibaba.fastjson.annotation.JSONField;
import com.xcity.db.entity.Build;
import com.xcity.db.entity.Employee;
import com.xcity.db.entity.Player;
import com.xcity.game.build.BuildLevelUpTemplate;
import com.xcity.pomelo.response.EmployeeInfoResponse.EmployeeSimpleInfo;

import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@PomeloMessage(type = Message.Type.RESPONSE)
public class BuildSpyResponse extends Response {
	
	protected long pid;
	protected int bid;
	@JSONField(name = "health")
	protected int risk; // 风险
	protected int income; // 每分钟收益
	protected int incomeAdded; // 每分钟额外收益
	protected int level; // 建筑等级
	protected int maxIncome; // 最大收益
	protected int price; // 出售价格
	protected List<EmployeeSimpleInfo> employees;
	
	public BuildSpyResponse(int serial, Player player, Build build) {
		super(serial);
//		build.update();
		this.pid = player.getId();
		this.bid = build.getId();
		BuildLevelUpTemplate lvlTemp = build.getBuildLevelUpTemplate();
		// 需要侦查的属性 SPY
		risk = lvlTemp.getRisk();
		int incomePerMinute = build.getIncomePerMinute();
		// SPY
		income = incomePerMinute;
		// SPY
		incomeAdded = (int) (incomePerMinute * build.getFactor() - incomePerMinute);
		// SPY
		level = build.getLevel();
		// SPY
		maxIncome = build.getMaxIncome();
		// SPY
		price = lvlTemp.getPrice();
		// SPY
		long[] employeeIds = build.employees();
		if (employeeIds != null) {
			Player owner = build.owner();
			employees = new ArrayList<EmployeeSimpleInfo>(employeeIds.length);
			for (long id : employeeIds) {
				Employee e;
				if (id != 0 && (e = owner.getEmployees().get(id)) != null) {
					employees.add(new com.xcity.pomelo.response.BuildStatusResponse.EmployeeSimpleInfo(e));
				} else {
					employees.add(EmployeeSimpleInfo.EMPTY);
				}
			}
		} else {
			employees = Collections.emptyList();
		}
	}
	
	public long getPid() {
		return pid;
	}

	public void setPid(long pid) {
		this.pid = pid;
	}

	public int getBid() {
		return bid;
	}

	public void setBid(int bid) {
		this.bid = bid;
	}

	public int getRisk() {
		return risk;
	}

	public void setRisk(int risk) {
		this.risk = risk;
	}

	public int getIncome() {
		return income;
	}

	public void setIncome(int income) {
		this.income = income;
	}

	public int getIncomeAdded() {
		return incomeAdded;
	}

	public void setIncomeAdded(int incomeAdded) {
		this.incomeAdded = incomeAdded;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public int getMaxIncome() {
		return maxIncome;
	}

	public void setMaxIncome(int maxIncome) {
		this.maxIncome = maxIncome;
	}

	public int getPrice() {
		return price;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	public List<EmployeeSimpleInfo> getEmployees() {
		return employees;
	}

	public void setEmployees(List<EmployeeSimpleInfo> employees) {
		this.employees = employees;
	}

}
